import Cookie from 'js-cookie'

export default {
    /**
     * 设置cookie
     * @param {string} key key
     * @param {Object} value value
     * @param {number} expiresTime 过期时间，单位毫秒
     */
    set: function (key, value, expiresTime) {
        if (!expiresTime) {
            Cookie.set(key, value)
            return
        }
        // 当前时间的时间戳
        let timestamp = Date.now();
        let time = new Date(timestamp+expiresTime)
        // console.log(time,timestamp)
        Cookie.set(key, value, {expires: time})
    },
    // 获取cookie
    get(key) {
        return Cookie.get(key)
    },
    // 判断cookie是否存在
    has(key) {
        return !!Cookie.get(key)
    },
    // 删除cookie
    remove(key) {
        Cookie.remove(key)
    },
}
